<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>路试详细项目</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../../css/weui.min.css">
    <script type="text/javascript" src="../../script/jquery-1.10.2.min.js"></script>
    <style>

    </style>
</head>
<body>
    <div class="container" id="container">
        <div id="divLXArea" class="weui_cells weui_cells_form" style="margin-top:0px">
            <div class="mainbutton">
                <a class="weui_btn weui_btn_primary" style="display:inline-block; width: 95%" href="javascript:;" id="btnLSStart" onclick="LSStartLX()"  >开  始</a>
            </div>
            <div class="weui_cells weui_cells_form">
                <div id="divKSSJ" class="weui_cells_title">开始时间:
                    <sapn id="spKSSJ" style="color:red">未开始</sapn>
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">检测线号</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <select class="select" style="width: 200px" id="selectLineNum">
                        <option value="1">1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">5</option>
                        <option value="6">6</option>
                        <option value="7">7</option>
                        <option value="8">8</option>
                        <option value="9">9</option>
                        <option value="10">10</option>
                    </select>
                </div>
            </div>  
        </div>
         <div id="divListHeader" class="weui_cells_title">
                <sapn id="spVehicleInfo"></sapn>
        </div>  
        <div class="weui_cells weui_cells_form">
            <div class="mainbutton">
                <a class="weui_btn weui_btn_default" style="display:inline-block; width: 95%" href="javascript:;" id="btnLSXCStart" onclick="LSXCStartLX()"  >行车路试开始</a>
            </div>
            <div class="space"></div>
            <div class="mainbutton">
                <a class="weui_btn weui_btn_default" style="display:inline-block; width: 95%" href="javascript:;" id="btnLSXCEnd" onclick="LSXCEndLX()"  >行车路试完成</a>
            </div>
            <div class="space"></div>
            <div id="divKSSJ" class="weui_cells_title">录像时间:
                <sapn id="spXCLXInfo" style="color:red">未开始</sapn>
            </div>  
            <div class="space"></div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">方向</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <select class="select" style="width: 200px" id="selectDirect">
                        <option value="1">正方向</option>
                        <option value="2">反方向</option>
                    </select>
                </div>
            </div>
            <div class="mainbutton">
                <a class="weui_btn weui_btn_default" style="display:inline-block; width: 95%" href="javascript:;" id="btnLSZCStart" onclick="LSZCStartLX()"  >驻车路试开始</a>
            </div>
            <div class="space"></div>
            <div class="mainbutton">
                <a class="weui_btn weui_btn_default" style="display:inline-block; width: 95%" href="javascript:;" id="btnLSZCEnd" onclick="LSZCEndLX()"  >驻车路试完成</a>
            </div>
            <div class="space"></div>
                <div id="divKSSJZF" class="weui_cells_title">正方向录像时间:
                <sapn id="spZCLXInfoZF" style="color:red">未开始</sapn>
            <div class="space"></div>
            </div>  
                <div id="divKSSJFF" class="weui_cells_title">反方向录像时间:
                <sapn id="spZCLXInfoFF" style="color:red">未开始</sapn>
            </div>  
             <div class="space"></div>
        </div>
        <div class="weui_cells_title">驻车路试计时：<span id="timeZC" style="font-size:30px;color:red">-</span>秒</div>
        <div class="mainbutton">
                <a class="weui_btn weui_btn_primary" style="display:inline-block; width: 95%" href="javascript:;" id="btnSaveLS" onclick="SaveLS()"  >提交路试信息</a>
            </div>  
    </div>
  
    <div class="space">      
    </div>
</body>
</html>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript">
    apiready = function(){
        $("#spVehicleInfo").html(api.pageParam.PlateNum + "," + api.pageParam.VIN);
        GetLSStatus();
    };

    function GetLSStatus()
    {
        var vUrlRead = $api.getStorage('ServerUrlRead');
        var vReadUrl = vUrlRead + '/WcfServices/GetLSXXInfo'+'/'+api.pageParam.ID;

        api.ajax({
            url:vReadUrl,
            method: 'post',
            contentType: "application/json",
        }, function(ret, err) {
            if (ret.IsSuccess) {
                var vLSKSSJ = "";
                if(ret.Data.KSSJ.length >0)
                {
                    vLSKSSJ = ret.Data.KSSJ;
                    $("#spKSSJ").html(vLSKSSJ);
                    $("#btnLSStart").removeClass("weui_btn_default");
                    $("#btnLSStart").addClass("weui_btn_primary");
                }

                $("#btnSaveLS").removeClass("weui_btn_default");
                $("#btnSaveLS").addClass("weui_btn_primary");

                var vXCKSSJ = "未开始";
                if(ret.Data.LSXCKSSJ.length >0)
                {
                    vXCKSSJ = ret.Data.LSXCKSSJ;
                    $("#btnLSXCStart").removeClass("weui_btn_default");
                    $("#btnLSXCStart").addClass("weui_btn_primary");
                }
                if(ret.Data.LSXCJSSJ.length >0)
                {
                    vXCKSSJ+= "-" + ret.Data.LSXCJSSJ;
                    $("#btnLSXCEnd").removeClass("weui_btn_primary");
                    $("#btnLSXCEnd").addClass("weui_btn_default");
                }
                else
                {
                    $("#btnLSXCEnd").removeClass("weui_btn_default");
                    $("#btnLSXCEnd").addClass("weui_btn_primary");
                }

                $("#spXCLXInfo").html(vXCKSSJ);


                var vZCKSSJ_ZF = "未开始";
                if(ret.Data.LSZCKSSJ_ZF.length >0)
                {
                    vZCKSSJ_ZF = ret.Data.LSZCKSSJ_ZF;
                    $("#btnLSZCStart").removeClass("weui_btn_default");
                    $("#btnLSZCStart").addClass("weui_btn_primary");
                }
                if(ret.Data.LSZCJSSJ_ZF.length >0)
                {
                    vZCKSSJ_ZF+= "-" +ret.Data.LSZCJSSJ_ZF;
                    $("#btnLSZCEnd").removeClass("weui_btn_primary");
                    $("#btnLSZCEnd").addClass("weui_btn_default");
                }
                else
                {
                    $("#btnLSZCEnd").removeClass("weui_btn_default");
                    $("#btnLSZCEnd").addClass("weui_btn_primary");
                }

                $("#spZCLXInfoZF").html(vZCKSSJ_ZF);


                var vZCKSSJ_FF = "未开始";
                if(ret.Data.LSZCKSSJ_FF.length >0)
                {
                    vZCKSSJ_FF = ret.Data.LSZCKSSJ_FF;
                    $("#btnLSZCStart").removeClass("weui_btn_default");
                    $("#btnLSZCStart").addClass("weui_btn_primary");
                }
                if(ret.Data.LSZCKSSJ_FF.length >0)
                {
                    vZCKSSJ_FF+= "-" + ret.Data.LSZCKSSJ_FF;
                    $("#btnLSZCEnd").removeClass("weui_btn_primary");
                    $("#btnLSZCEnd").addClass("weui_btn_default");
                }
                else
                {
                    $("#btnLSZCEnd").removeClass("weui_btn_default");
                    $("#btnLSZCEnd").addClass("weui_btn_primary");
                }

                $("#spZCLXInfoFF").html(vZCKSSJ_FF);
            }
        });
    }

    function LSStartLX()
    {
        var vClass = $("#btnLSStart").attr("class");
        var array=vClass.split(" "); 

        var vEnable = false;
        for(var i = 0;i<array.length;i++)
        {
            if(array[i] == "weui_btn_primary")
            {
                vEnable = true;
                break;
            }
        }

        if(vEnable)
        {   
            $("#btnLSStart").removeClass("weui_btn_primary");
            $("#btnLSStart").addClass("weui_btn_default");
            var vUrlWrite = $api.getStorage('ServerUrlWrite');
            var vJCXDH = $("#selectLineNum").val();

            api.ajax({
                url:vUrlWrite + '/WcfServices/LSXMStart/'+api.pageParam.ID + '/'+ vJCXDH,
                method: 'post',
                contentType: "application/json",
            }, function(ret, err) {
                if (ret.IsSuccess) {
                    $("#btnLSStart").removeClass("weui_btn_default");
                    $("#btnLSStart").addClass("weui_btn_primary");
                    $("#btnLSXCStart").removeClass("weui_btn_default");
                    $("#btnLSXCStart").addClass("weui_btn_primary");
                    $("#btnLSZCStart").removeClass("weui_btn_default");
                    $("#btnLSZCStart").addClass("weui_btn_primary");
                    $("#spKSSJ").html(ret.Data);
                }
                else
                {
                     api.alert({
                         title: '错误',
                         msg:  ret.Message,
                         }, function(ret, err){
                         
                     });      
                    $("#btnLSStart").removeClass("weui_btn_default");
                    $("#btnLSStart").addClass("weui_btn_primary");                 
                }
            });
        }   
    }


    function LSXCStartLX()
    {
        var vClass = $("#btnLSXCStart").attr("class");
        var array=vClass.split(" "); 

        var vEnable = false;
        for(var i = 0;i<array.length;i++)
        {
            if(array[i] == "weui_btn_primary")
            {
                vEnable = true;
                break;
            }
        }

        if(vEnable)
        {
            $("#btnLSXCStart").removeClass("weui_btn_primary");
            $("#btnLSXCStart").addClass("weui_btn_default");
            var vUrlWrite = $api.getStorage('ServerUrlWrite');
            var vJCXDH = $("#selectLineNum").val();

            api.ajax({
                url:vUrlWrite + '/WcfServices/LSXCStart/'+api.pageParam.ID + '/'+ vJCXDH,
                method: 'post',
                contentType: "application/json",
            }, function(ret, err) {
                if (ret.IsSuccess) {
                    $("#btnLSXCEnd").removeClass("weui_btn_default");
                    $("#btnLSXCEnd").addClass("weui_btn_primary");
                    $("#spXCLXInfo").html(ret.Data);
                }
                else
                {
                     api.alert({
                         title: '提示',
                         msg:  ret.Message,
                         }, function(ret, err){
                         
                     });      
                    $("#btnLSXCStart").removeClass("weui_btn_default");
                    $("#btnLSXCStart").addClass("weui_btn_primary");                 
                }
            });
        }
    }

    function LSXCEndLX()
    {
        var vClass = $("#btnLSXCEnd").attr("class");
        var array=vClass.split(" "); 

        var vEnable = false;
        for(var i = 0;i<array.length;i++)
        {
            if(array[i] == "weui_btn_primary")
            {
                vEnable = true;
                break;
            }
        }

        if(vEnable)
        {
            $("#btnLSXCEnd").removeClass("weui_btn_primary");
            $("#btnLSXCEnd").addClass("weui_btn_default");
            var vUrlWrite = $api.getStorage('ServerUrlWrite');
            var vUserCHName = $api.getStorage('UserCHName');
            var vUserSFZH = $api.getStorage('UserSFZH');
            api.ajax({
                url:vUrlWrite + '/WcfServices/LSXCEnd/'+api.pageParam.ID + '/'+ vUserCHName+ '/'+ vUserSFZH,
                method: 'post',
                contentType: "application/json",
            }, function(ret, err) {
                if (ret.IsSuccess) {
                    $("#btnLSStart").removeClass("weui_btn_default");
                    $("#btnLSStart").addClass("weui_btn_primary"); 
                    $("#btnLSXCEnd").removeClass("weui_btn_primary");
                    $("#btnLSXCEnd").addClass("weui_btn_default");
                    $("#spXCLXInfo").html(ret.Data); 
                }
                else
                {
                     api.alert({
                         title: '提示',
                         msg:  ret.Message,
                         }, function(ret, err){
                         
                     });      
                    $("#btnLSXCEnd").addClass("weui_btn_primary");
                    $("#btnLSXCEnd").removeClass("weui_btn_default");         
                }
            });
        }
    }

    function after(iCount){
        $("#timeZC").html(iCount);
        iCount=iCount+1;
        setTimeout(function(){
            if(iCount < 121)
            {
                after(iCount);  
            }
        },1000);
    }

    function CountingUp(iSumCount)
    {
        $(function(){
            setTimeout(function(){
            //设置提交按钮样式
            $("#btnLSZCEnd").removeClass("weui_btn_default");
            $("#btnLSZCEnd").addClass("weui_btn_primary");

            $("#btnLSZCStart").removeClass("weui_btn_primary");
            $("#btnLSZCStart").addClass("weui_btn_default");

            },iSumCount*1000);
                after(iSumCount);
        });
    }

    function SaveLS()
    {
        var vClass = $("#btnSaveLS").attr("class");
        var array=vClass.split(" "); 

        var vEnable = false;
        for(var i = 0;i<array.length;i++)
        {
            if(array[i] == "weui_btn_primary")
            {
                vEnable = true;
                break;
            }
        }

        if(vEnable)
        {
            $("#btnSaveLS").removeClass("weui_btn_primary");
            $("#btnSaveLS").addClass("weui_btn_default");
            var vUserCHName = $api.getStorage('UserCHName');
            var vUserSFZH = $api.getStorage('UserSFZH');
            var vUrlWrite = $api.getStorage('ServerUrlWrite');

            $.ajax({
                type: 'Post',
                url: vUrlWrite + '/WcfServices/SubmitLSXXData',
                contentType: "application/json", //必须有
                async: false,
                dataType: "json", //表示返回值类型，不必须
                    //data: JSON.stringify({ 'UserName': 'admin', 'UserPwd': '123456' }),  //相当于 //data: "{'str1':'foovalue', 'str2':'barvalue'}",
                data: JSON.stringify({
                    'PId': api.pageParam.ID,
                    'UserCHName': vUserCHName,
                    'UserSFZH': vUserSFZH
                }),
                success: function(ret) {
                    if (ret.SubmitLSXXDataResult) {
                        if(ret.SubmitLSXXDataResult.IsSuccess)
                        {
                            RefreshLSHome();
                        }
                        else
                        {
                            api.alert({
                                title: '错误',
                                msg: ret.SubmitLSXXDataResult.Message,
                            }, function(ret, err){
                            });
                            $("#btnSaveLS").removeClass("weui_btn_default");
                            $("#btnSaveLS").addClass("weui_btn_primary");
                        }
                    } else {
                        alert(JSON.stringify(ret));
                        $("#btnSaveLS").removeClass("weui_btn_default");
                        $("#btnSaveLS").addClass("weui_btn_primary");
                    }
                },
                error: function(data, status, e) {
                    alert(e);
                }
            });
        }
    }
    function RefreshLSHome()
    {
        api.openWin({
            name: 'win_lshome',
            url: 'win_lshome.html',
            bounces: false,
            delay: 200,
            reload:true,
        });

        api.closeWin({
            name: 'win_lsxx',
            url: 'win_lsxx.html',
        });
    }

    function LSZCStartLX()
    {
        var vClass = $("#btnLSZCStart").attr("class");
        var array=vClass.split(" "); 

        var vEnable = false;
        for(var i = 0;i<array.length;i++)
        {
            if(array[i] == "weui_btn_primary")
            {
                vEnable = true;
                break;
            }
        }

        if(vEnable)
        {
            $("#btnLSZCStart").removeClass("weui_btn_primary");
            $("#btnLSZCStart").addClass("weui_btn_default");
            var vUrlWrite = $api.getStorage('ServerUrlWrite');
            var vJCXDH = $("#selectLineNum").val();
            var vCLFX = $("#selectDirect").val();

            api.ajax({
                url:vUrlWrite + '/WcfServices/LSZCStart/'+api.pageParam.ID + '/'+ vJCXDH + '/' + vCLFX,
                method: 'post',
                contentType: "application/json",
            }, function(ret, err) {
                if (ret.IsSuccess) {
                    $("#btnLSZCEnd").removeClass("weui_btn_default");
                    $("#btnLSZCEnd").addClass("weui_btn_primary");
                    if(vCLFX == "1")
                    {
                        $("#spZCLXInfoZF").html(ret.Data);
                    }
                    else
                    {
                        $("#spZCLXInfoFF").html(ret.Data);
                    }

                    var vSeconds = 1;
                    CountingUp(vSeconds);
                }
                else
                {
                     api.alert({
                         title: '提示',
                         msg:  ret.Message,
                         }, function(ret, err){
                         
                     });      
                    $("#btnLSZCStart").removeClass("weui_btn_default");
                    $("#btnLSZCStart").addClass("weui_btn_primary");                 
                }
            });
        }       
    }

    function LSZCEndLX()
    {
        var vClass = $("#btnLSZCEnd").attr("class");
        var array=vClass.split(" "); 

        var vEnable = false;
        for(var i = 0;i<array.length;i++)
        {
            if(array[i] == "weui_btn_primary")
            {
                vEnable = true;
                break;
            }
        }

        if(vEnable)
        {
            $("#btnLSZCEnd").removeClass("weui_btn_primary");
            $("#btnLSZCEnd").addClass("weui_btn_default");
            var vUrlWrite = $api.getStorage('ServerUrlWrite');
            var vUserCHName = $api.getStorage('UserCHName');
            var vUserSFZH = $api.getStorage('UserSFZH');
            var vCLFX = $("#selectDirect").val(); //车辆方向

            api.ajax({
                url:vUrlWrite + '/WcfServices/LSZCEnd/'+api.pageParam.ID + '/'+ vUserCHName+ '/'+ vUserSFZH+ '/' + vCLFX,
                method: 'post',
                contentType: "application/json",
            }, function(ret, err) {
                if (ret.IsSuccess) {
                    $("#btnLSZCStart").removeClass("weui_btn_default");
                    $("#btnLSZCStart").addClass("weui_btn_primary"); 
                    $("#btnLSZCEnd").removeClass("weui_btn_primary");
                    $("#btnLSZCEnd").addClass("weui_btn_default");
                     if(vCLFX == "1")
                    {
                        $("#spZCLXInfoZF").html(ret.Data);
                    }
                    else
                    {
                        $("#spZCLXInfoFF").html(ret.Data);
                    } 
                }
                else
                {
                     api.alert({
                         title: '提示',
                         msg:  ret.Message,
                         }, function(ret, err){
                         
                     });      
                    $("#btnLSZCEnd").addClass("weui_btn_primary");
                    $("#btnLSZCEnd").removeClass("weui_btn_default");         
                }
            });
        }
    }
</script>